package com.dify.tool.common.utils;

import java.util.List;
import java.util.function.Consumer;

/**
 * @Author kjh
 * @Date 2024/8/8 14:28
 */
public class ForEachUtil {
    public static <T> void doForEach(List<T> list, Consumer<? super T> action){
        int end = list.size() - 1;
        int start = 0;
        while (start <= end) {
            action.accept(list.get(start));
            //避免重复设置
            if (start == end) break;
            action.accept(list.get(end));
            ++start;
            --end;
        }
    }
}
